package com.dtsheep.rxjava.stduy;

import rx.Observable;
import rx.Subscriber;
import rx.schedulers.Schedulers;

import java.util.HashMap;
import java.util.Map;

/**
 * SubTest
 *
 * <p>
 * </p>
 *
 * @author chuanbai
 * @date 2024/9/18
 */
public class SubTest {


    public static void main(String[] args) {

        Observable<Map> observable1 = Observable.unsafeCreate((Subscriber<? super Map> s) -> {
            s.onNext(getHashMap1());
            s.onCompleted();
        }).subscribeOn(Schedulers.io());

//        Observable<Map> observable2 = Observable.just(getHashMap2());

        Observable<Map> observable2 = Observable.unsafeCreate((Subscriber<? super Map> s) -> {
            s.onNext(getHashMap2());
            s.onCompleted();
        }).subscribeOn(Schedulers.io());


        Observable<Map> mapObservable = observable1.concatWith(observable2);
//        Map first = mapObservable.toBlocking().first();
//        System.out.println("first: " + first);

        HashMap<Object, Object> hashMap = new HashMap<>();
        mapObservable.subscribe(hashMap::putAll);

        Map first = mapObservable.toBlocking().first();
        System.out.println(first);

        System.out.println("hashmap 订阅：" + hashMap);


        Observable<String> observable = Observable.just("11111");
        System.out.println(observable.toBlocking().first());

    }

    public static Map getHashMap1(){
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("1","111");
        return hashMap;
    }

    public static Map getHashMap2(){
        HashMap<String, String> hashMap2 = new HashMap<>();
        hashMap2.put("2","222");
        return hashMap2;
    }
}
